      * cobc -x principal.cbl  gestor_archivo.cbl -o subprogramas.exe
      ******************************************************************
       IDENTIFICATION DIVISION.
      ******************************************************************
       PROGRAM-ID. gestor_archivo.

      ******************************************************************
       ENVIRONMENT DIVISION.
      ******************************************************************
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
        SELECT ArchivoEntrada ASSIGN TO "CLIENTES.BIN"
        ORGANIZATION IS INDEXED
        ACCESS IS DYNAMIC
        RECORD KEY IS K-COD-CLI
        FILE STATUS IS FS-CLI.
      ******************************************************************
       DATA DIVISION.
      ******************************************************************
      *****************************************************
       FILE SECTION.
      *****************************************************
        FD ArchivoEntrada LABEL RECORD STANDARD.
        01 RegistroEntrada.
         03 K-COD-CLI.
            05 COD-CLI      PIC 9(08).
         03 NOMBRE-CLI      PIC X(30).
         03 DIRECCION-CLI   PIC X(30).
         03 TEL-CLI         PIC X(15).
         03 FEC-NAC         PIC X(10).
         03 OCUPACION       PIC X(20).
      *****************************************************
       WORKING-STORAGE SECTION.
      *****************************************************
       01 FS-CLI            PIC 9(2).

      *****************************************************
       LINKAGE SECTION.
      *****************************************************
       01 operacion         PIC X(01).
       01 registro.
         03 COD-CLI         PIC 9(08).
         03 NOMBRE-CLI      PIC X(30).
         03 DIRECCION-CLI   PIC X(30).
         03 TEL-CLI         PIC X(15).
         03 FEC-NAC         PIC X(10).
         03 OCUPACION       PIC X(20).
       01 fs-clientes       PIC X(02).

      ******************************************************************
       PROCEDURE DIVISION USING operacion, registro, fs-clientes.
      ******************************************************************
         Inicio.
            EVALUATE operacion
              WHEN 'O' PERFORM open-clientes
              WHEN 'A' PERFORM open-io-clientes
              WHEN 'C' PERFORM close-clientes
              WHEN 'R' PERFORM read-clientes
              WHEN 'W' PERFORM write-clientes
              WHEN 'U' PERFORM rewrite-clientes
              WHEN 'D' PERFORM delete-clientes
              WHEN other PERFORM oper-error
            END-EVALUATE.
      ******************************************************************
         open-clientes.
            OPEN INPUT ArchivoEntrada
            MOVE FS-CLI TO fs-clientes
            GOBACK.
      ******************************************************************
         open-io-clientes.
            OPEN I-O ArchivoEntrada
            MOVE FS-CLI TO fs-clientes
            GOBACK.
      ******************************************************************
         close-clientes.
            CLOSE ArchivoEntrada
            MOVE FS-CLI TO fs-clientes
            GOBACK.
      ******************************************************************
         read-clientes.
            MOVE COD-CLI OF registro
              TO COD-CLI OF RegistroEntrada
            READ ArchivoEntrada END-READ
            MOVE FS-CLI TO fs-clientes
            IF FS-CLI = "00"
               PERFORM completar-registro
            END-IF
            GOBACK.
      ******************************************************************
         write-clientes.
           MOVE COD-CLI OF registro TO COD-CLI OF RegistroEntrada
           READ ArchivoEntrada END-READ
           IF FS-CLI = "23"
              PERFORM completar-reg-Entrada
              WRITE RegistroEntrada END-WRITE
              MOVE FS-CLI TO fs-clientes
           END-IF
           GOBACK.
      ******************************************************************
         rewrite-clientes.
           MOVE COD-CLI OF registro TO COD-CLI OF RegistroEntrada
           READ ArchivoEntrada INTO RegistroEntrada END-READ
           IF FS-CLI = "00"
              PERFORM completar-reg-Entrada
              REWRITE RegistroEntrada END-REWRITE
              MOVE FS-CLI TO fs-clientes
           END-IF
           GOBACK.
      ******************************************************************
         delete-clientes.
           MOVE COD-CLI OF registro TO COD-CLI OF RegistroEntrada
           READ ArchivoEntrada INTO RegistroEntrada END-READ
           IF FS-CLI = "00"
              DELETE ArchivoEntrada END-DELETE
              MOVE FS-CLI TO fs-clientes
           END-IF
           GOBACK.
      ******************************************************************
         oper-error.
           DISPLAY "Operacion desconocida".
           DISPLAY Operacion.
           GOBACK.
      ******************************************************************
          completar-registro.
               MOVE COD-CLI       OF RegistroEntrada
              TO COD-CLI       OF registro
            MOVE NOMBRE-CLI    OF RegistroEntrada
              TO NOMBRE-CLI    OF registro
            MOVE DIRECCION-CLI OF RegistroEntrada
              TO DIRECCION-CLI OF registro
            MOVE TEL-CLI       OF RegistroEntrada
              TO TEL-CLI       OF registro
            MOVE FEC-NAC       OF RegistroEntrada
              TO FEC-NAC       OF registro
            MOVE OCUPACION     OF RegistroEntrada
              TO OCUPACION     OF registro.
      ******************************************************************
          completar-reg-Entrada.
               MOVE COD-CLI       OF registro
              TO COD-CLI       OF RegistroEntrada
            MOVE NOMBRE-CLI    OF registro
              TO NOMBRE-CLI    OF RegistroEntrada
            MOVE DIRECCION-CLI OF registro
              TO DIRECCION-CLI OF RegistroEntrada
            MOVE TEL-CLI       OF registro
              TO TEL-CLI       OF RegistroEntrada
            MOVE FEC-NAC       OF registro
              TO FEC-NAC       OF RegistroEntrada
            MOVE OCUPACION     OF registro
              TO OCUPACION     OF RegistroEntrada.
